import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/widget/custom_app_bar.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:webview_all/webview_all.dart';

class MyWebViewPage extends StatefulWidget {
  const MyWebViewPage({super.key});
  static const path = '/webView';

  @override
  State<MyWebViewPage> createState() => _MyWebViewPageState();
}

class _MyWebViewPageState extends State<MyWebViewPage> {
  // late WebViewController _controller;
  late var url = '';

  @override
  void initState() {
    super.initState();
    try {
      final params = Get.parameters ?? {};
      final args = Get.arguments ?? {};
      var getUrl = params['url'] ?? args['url'];

      if (getUrl != null) {
        url = Uri.decodeComponent(getUrl);
        // print('$getUrl ==== getUrl');
      } else {
        Get.back();
        Get.snackbar('错误', 'URL 无效');
      }
    } catch (e) {
      debugPrint('解析 URL 失败: $e');
      Get.back();
      Get.snackbar('错误', 'URL 格式不正确');
    }
  }

  @override
  void dispose() {
    // _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
      SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.black, // 状态栏颜色
    statusBarIconBrightness: Brightness.dark, // 状态栏图标亮度
    systemNavigationBarColor: Colors.black, // 导航栏颜色
    systemNavigationBarIconBrightness: Brightness.dark, // 导航栏图标亮度
  ));
    return SafeArea(
      child: Scaffold(
        appBar: CustomAppBar2(title: '', context: context),
        body: Container(
          color: Colors.white,
          child: Webview(url: url),
        ),
      ),
    );
  }
}
